/**
 * @description:混入对象
 */
export const mymixin = {
  data() {
    return {

      // 弹窗是否能修改
      mixDialogDisabled: false,
      nowpage: 1,
      loading: false,
      // 添加删除修改状态---主要通过此状态来判断调用方法
      nowChanceStau: '',
      // 操作按钮的逻辑及展示数据
      addActive: true,
      delActive: false,
      saveActive: false,
      cancelActive: false,
      editActive: false,
      dialogFormVisible: false,
      // 表格数据
      tableData: [],
      formData: {},
      // 表单数据
      treeData: [],
      // 当前页
      currentPage: 1,
      // 每页的数据条数
      pageSize: 10,
      // 总条数
      totalSize: 0,
      // 总页数
      totalPages: 0,
      rightTableData: [],
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        },
        {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        },
        {
          text: '最近一年',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 365);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      // 弹出框添加修改
      titleText: null,
      currentRow: null,
      editObject: {},
      showAddEditDialog: false,
      // 搜索框的显示与隐藏
      activeName: '',
      // 查看视频
      showVideoDialog: false,
      // 查看图片
      showPictureDialog: false,
      // 查看关键字
      showKeyDialog: false,
      // 查看详情原因
      showReasonDialog: false,
      searchObj: {}
    }
  },
  created() {
    this.token = sessionStorage.getItem("token");
  },
  watch: {
    nowChanceStau(newval) {
      // 当状态为删除的时候触发删除方法---另外的删除修改添加，通过点击保存，调用方法来实现
      if (newval === 'del') {
        this.delmessage()
      }
    }
  },
  computed: {
    headers() {
      return {
        "loginToken": sessionStorage.getItem("token"),
        "organizationId": sessionStorage.organizationId,
        "sysDataBaseName": "DB_TDW1_OM1"
      }
    }
  },
  methods: {
    handleChange() {
    },

    mixTableUpdatePlus(e) {
      // console.log("mixTableUpdatePlus");
      this.searchObj = e;
      this.currentPage = 1;
      this.queryPageList(e)
    },
    changePageSize(pageSize) {
      this.pageSize = pageSize;
      this.queryPageList(this.searchObj);
    },
    changeCurrentPage(currentPage) {
      this.currentPage = currentPage;
      this.queryPageList(this.searchObj);
    },
    // select搜索框
    changeSelect() {
      if (this.activeName === '') {
        this.activeName = '1'
      } else if (this.activeName === '1') {
        this.activeName = ''
      }
    },
    // 填充表格空白行
    addblankmet() {
      let havline = this.tableData.length % this.pageSize
      if (this.tableData.length < this.pageSize) {
        if (havline < this.pageSize) {
          const remain = this.pageSize - havline;
          for (var i = 0; i < remain; i++) {
            this.tableData.push({ 'index': i + this.tableData.length - 1 });
          }
        }
      }
    },
    handleCurrentChange(val) {
      this.currentRow = val;
    },
    // 默认全选不选
    toggleNoSelection(rows) {
      if (rows) {
        this.$nextTick(() => {
          rows.forEach(row => {
            this.$refs.tableData.toggleRowSelection(row, false);
          });
        })
      } else {
        this.$refs.tableData.clearSelection();
      }
    },
    // 添加
    add(ruleForm) {
      this.nowChanceStau = 'add'
      this.titleText = "添加"
      this.addActive = false;
      this.delActive = false;
      this.showAddEditDialog = true
      this.$nextTick(() => {
        this.$refs[ruleForm || 'ruleForm']?.clearValidate();
      });
      this.addPlus();
    },
    addPlus() {

    },
    // 删除
    del() {
      this.$confirm("此操作将永久删除该类型, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        customClass: "myClass"
      })
        .then(() => {
          this.nowChanceStau = 'del'
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
          if (this.tableData.length > 0) {
            this.$refs.tableData.clearSelection();
          } else if (this.treeData.length > 0) {
            this.$refs.tree.setCheckedKeys([]);
          }
        });
      this.addActive = true;
      this.delActive = false;
    },
    // 修改
    edit(data) {
      this.nowChanceStau = 'edit'
      this.titleText = "修改"
      this.addActive = false;
      this.delActive = false;
      this.showAddEditDialog = true
      this.mixDialogDisabled = false

      data && this.handleEdit && this.handleEdit(data)
      this.$nextTick(() => {
        this.$refs['ruleForm']?.clearValidate();
      });
    },
    // 取消
    cancel() {
      this.nowChanceStau = '';
      this.titleText = ''
      this.rightTableData = [];
      this.editObject = {}
      this.addActive = true;
      this.delActive = false;
      this.showAddEditDialog = false
      this.showPictureDialog = false
      this.showhitchApplyDialog = false
      this.showVideoDialog = false
      this.showKeyDialog = false
      this.showReasonDialog = false

      this.$nextTick(() => {
        this.$refs['ruleForm']?.clearValidate();
        this.$refs['ruleForm']?.resetFields();
      });
      // this.$refs.tableData.setCurrentRow()
      // this.$refs.tableData.clearSelection()
    },
    // 初始化操作栏状态
    resetActionBar(FormData) {
      this.nowChanceStau = ''
      this.showAddEditDialog = false;
      this.showPictureDialog = false
      this.showhitchApplyDialog = false
      this.showVideoDialog = false
      this.showKeyDialog = false
      this.showReasonDialog = false
      this.nocheckActive = false
      this.addActive = true;
      this.delActive = false;
      if (FormData) {
        // this.$refs.tableData.setCurrentRow()
        // this.$refs.tableData.clearSelection()

        this.$nextTick(() => {
          this.$refs['ruleForm']?.clearValidate();
        });
      }
    },
    closeDialog() {
      if (this.showAddEditDialog === true || this.showReasonDialog === true) {
        this.queryPageList()
      }
      this.showAddEditDialog = false
      this.showhitchApplyDialog = false
      this.showPictureDialog = false
      this.showVideoDialog = false
      this.showKeyDialog = false
      this.showReasonDialog = false
      this.nocheckActive = false
      this.nowChanceStau = '';
      this.titleText = ''
      this.editObject = {}
      this.addActive = true;
      this.delActive = false;

      this.$nextTick(() => {
        this.$refs['ruleForm']?.clearValidate();
      });
      // this.$refs.tableData.setCurrentRow()
      // this.$refs.tableData.clearSelection()
    }
  }
}
